import java.util.HashMap;
import java.util.Map;


public class InstructionType {
 Map <String, Integer> instructions ;
 Map <String, String> binaryInstructions ;
 /*R-type 0
  * I-type 1
  * Memory  Reference 2
  * Branch 3
  * Jump 4
*/
 
 public InstructionType()
 {	
	 this.binaryInstructions = new HashMap<String, String> ();
	 this.instructions = new HashMap<String, Integer> ();
	 this.instructions.put("add",0 );
	 this.instructions.put("sub",0 );
	 this.instructions.put("and",0 );
	 this.instructions.put("or",0 );
	 this.instructions.put("nor",0 );
	 this.instructions.put("slt",0 );
	 this.instructions.put("sltu",0 );
	 this.instructions.put("addi",1 );
	 this.instructions.put("andi",1 );
	 this.instructions.put("ori",1 );
	 this.instructions.put("slti",1 );
	 this.instructions.put("sltui",1 );
	 this.instructions.put("sll",1);
	 this.instructions.put("srl",1);
	 this.instructions.put("lw",2);
	 this.instructions.put("sw",2);
	 this.instructions.put("beq",3);
	 this.instructions.put("bne",3 );
	 this.instructions.put("j",4 );
	 this.instructions.put("jal",4 );
	 this.instructions.put("jr", 4);
	 
	 
 }
 
 public boolean isInstruction(String key) {
	 return this.instructions.containsKey(key);
 }
 
 public int getInstructionType(String key){
	 return this.instructions.get(key);
 }
 
 public void initiateBinaryInstructions(){
	 this.binaryInstructions.put("add","100000");
	 this.binaryInstructions.put("sub","100010");
	 this.binaryInstructions.put("and","100100" );
	 this.binaryInstructions.put("or","100101");
	 this.binaryInstructions.put("nor","100111");
	 this.binaryInstructions.put("slt","101010");
	 this.binaryInstructions.put("sltu","101011");
	 this.binaryInstructions.put("addi","001000");
	 this.binaryInstructions.put("andi","001100");
	 this.binaryInstructions.put("ori","001101");
	 this.binaryInstructions.put("slti","001010");
	 this.binaryInstructions.put("sltui","001011");
	 this.binaryInstructions.put("sll","000000");
	 this.binaryInstructions.put("srl","000010");
	 this.binaryInstructions.put("lw","100011");
	 this.binaryInstructions.put("sw","101011");
	 this.binaryInstructions.put("beq","000100");
	 this.binaryInstructions.put("bne","000101");
	 this.binaryInstructions.put("j","000010");
	 this.binaryInstructions.put("jal","000011");
	 this.binaryInstructions.put("jr","001000");
 }

 public String getBinaryRep(String key){
	 return this.binaryInstructions.get(key);
 }
}
